/*
 * @Date: 2025-09-22 18:04:11
 * @Auth: 463997479@qq.com
 * @LastEditors: 463997479@qq.com
 * @LastEditTime: 2025-09-28 15:15:54
 * @FilePath: \corpus\src\pages\resourceManagement\list\component\AddModalKnowledge\index.tsx
 */
/*
 * @Date: 2025-09-11 14:54:39
 * @Auth: 463997479@qq.com
 * @LastEditors: 463997479@qq.com
 * @LastEditTime: 2025-09-11 17:12:08
 * @FilePath: \corpus\src\pages\resourceManagement\list\component\AddModalKnowledge\index.tsx
 */
import { OPENENUM, SENSITIVEENUM } from '@/enum';
import { Form, Input, Modal, Radio, Select } from 'antd';
import { useEffect } from 'react';
import hooks from '../../hooks';
const normFile = (e: any) => {
  if (Array.isArray(e)) {
    return e;
  }
  return e?.fileList;
};
export default () => {
  const {
    setModalKnowledgeVisible,
    tabsType,
    resourceKnowledgeData,
    modalKnowledgeVisible,
    forKnowledgemRef,
    editKnowledgeContent,
    addNewKnowledgeContent,
    setResourceKnowledgeData,
    tabKey,
  } = hooks.useContainer();
  const tabName = tabKey === 'file' ? '资源' : '知识库';

  const handleSubmit = () => {
    forKnowledgemRef.validateFields().then((vals) => {
      const methodKnowledge = resourceKnowledgeData ? editKnowledgeContent : addNewKnowledgeContent;
      methodKnowledge.run({
        ...vals,
        isHeightQuality:1
      });
    });
  };

  useEffect(() => {
    if (modalKnowledgeVisible && resourceKnowledgeData) {
      forKnowledgemRef.setFieldsValue({
        ...(resourceKnowledgeData as Record<string, any>),
      });
    } else {
      forKnowledgemRef.resetFields();
      setResourceKnowledgeData(null);
    }
  }, [resourceKnowledgeData, modalKnowledgeVisible]);
  return (
    <Modal
      width={600}
      title={`${resourceKnowledgeData ? '修改' : '创建'}${tabsType[tabKey].name}`}
      open={modalKnowledgeVisible}
      onCancel={() => {
        setModalKnowledgeVisible(false);
      }}
      okText="确认"
      onOk={handleSubmit}
    >
      <Form form={forKnowledgemRef} labelCol={{ span: 6 }}>
        <Form.Item name="id" hidden />

        <Form.Item name="name" label={`${tabName}名称`} rules={[{ required: true }]}>
          <Input disabled={resourceKnowledgeData ? true : false} placeholder="请输入"></Input>
        </Form.Item>
{/* 
        <Form.Item
          label={`是否高质量数据集`}
          name="isHeightQuality"
          rules={[{ required: true, message: '请选择' }]}
        >
          <Radio.Group
            onChange={(val) => {}}
            disabled={resourceKnowledgeData ? true : false}
            options={[
              { label: '是', value: 1 },
              { label: '否', value: 0 },
            ]}
          />
        </Form.Item> */}
        <Form.Item
          label={`${tabName}公开属性`}
          name="openProperty"
          rules={[{ required: true, message: '请选择' }]}
        >
          <Select disabled={resourceKnowledgeData ? true : false} placeholder="请选择">
            <Select.Option value={OPENENUM.PUBLICP}>无条件公开</Select.Option>
            <Select.Option value={OPENENUM.DEPT}>部门公开</Select.Option>
            <Select.Option value={OPENENUM.PROTECTED}>有条件公开</Select.Option>
            <Select.Option value={OPENENUM.PRIVATE}>不予公开</Select.Option>
          </Select>
        </Form.Item>
        <Form.Item
          label={`${tabName}敏感等级`}
          name="sensitiveLevel"
          rules={[{ required: true, message: '请选择敏感等级' }]}
        >
          <Select disabled={resourceKnowledgeData ? true : false} placeholder="请选择">
            <Select.Option value={SENSITIVEENUM.NO_SENSITIVE}>L1不敏感</Select.Option>
            <Select.Option value={SENSITIVEENUM.LOW_SENSITIVE}>L2低敏感</Select.Option>
            <Select.Option value={SENSITIVEENUM.LITTLE_SENSITIVE}>L3较敏感</Select.Option>
            <Select.Option value={SENSITIVEENUM.SENSITIVE}>L4敏感</Select.Option>
          </Select>
        </Form.Item>
        <Form.Item name="knowledgeDescribe" label="描述" rules={[{ required: true }]}>
          <Input.TextArea placeholder="请输入内容"></Input.TextArea>
        </Form.Item>
      </Form>
    </Modal>
  );
};
